Quest = {}
QuestFunc = {}
QuestFunc.__index = QuestFunc
setmetatable(Quest, QuestFunc)

QuestFunc.create = function(self, qid)
  local q = {}
  setmetatable(q, QuestFunc)
  q.info = self:getQuestInfo(qid)
  if q.info==nil then
    return nil
  end 
  local qs = q.info.questIds
  local questItems = {}
  if #qs==0 then
    questItems[#questItems+1] = qid 
  else
    for k,v in pairs(qs) do
      questItems[#questItems+1] = v
    end
  end
  q.subQuests = questItems
  return q
end

QuestFunc.getLevel= function(self)
  if self.info.type~="daily" then
    return 0
  end
  return UserData.userinfo.host.current.d[tostring(self.info.id)].s
end

QuestFunc.getPoint = function(self)
  local level = self:getLevel()--self.info.level
  print("QuestFunc.getPoint", level)
  if level==1 then
    return 3;
  elseif level==2 then
    return 4;
  elseif level==3 then
    return 6;
  elseif level==4 then
    return 9;
  elseif level==5 then
    return 12;
  else
    return 3
  end
end
QuestFunc.checkComplete = function(self)
  local flag=true
  for k, v in pairs(self.subQuests) do
    local tq = Quest:create(v)
    if tq.info~=nil then
      local total = 0
      if tq.info.threshold~=nil then total=tq.info.threshold;end
      local cur = 0
      local tmp = UserData.userinfo.host.currentQuests[tostring(v)]
      if tmp~=nil then cur=tmp;end
      print("RenWuSceneFunc.checkRenWuComplete", tq.info.id, v, total, cur)
      if total>0 and total>cur then
        flag = false
        break
      end
    end
  end
  return flag
end

QuestFunc.getQuestInfo = function(self, qid)
  for k,v in pairs(UserData.userinfo.quests) do
    if v.id==qid then
      return v
    end
  end
end

